﻿using System;
using Microsoft.Practices.ServiceLocation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DomainModel.Tests
{
    [TestClass]
    public class SignalementFixture
    {
        [TestInitialize]
        public void OnBeforeTest()
        {
            var testConfigurer = new TestConfigurer();
            testConfigurer.Configure();
        }

        [TestMethod]
        public void CanCreateSignalementUrgent()
        {
            // Prepare
            var beginDate = new DateTime(2012, 2, 7);
            var panneRepository = ServiceLocator.Current.GetInstance<IPanneRepository>();
            var objetPatrimonialRepository = ServiceLocator.Current.GetInstance<IObjetPatrimonialRepository>();
            panneRepository.Add(new Panne("FAKE", "Panne Grave", PanneSeverity.Serious) {Id = 1});
            objetPatrimonialRepository.Add(new ObjetPatrimonial("FAKE", "Vieux Feu rouge") {Id = 1, Age = 17});

            // Act
            var signalementWithAutomaticDelay = Signalement.CreateSignalementWithAutomaticDelay(1, 1, beginDate, "Test");
            
            // Verify
            Assert.IsNotNull(signalementWithAutomaticDelay);
            Assert.IsTrue(signalementWithAutomaticDelay.IsUrgent);
            Assert.AreEqual(beginDate.AddHours(3), signalementWithAutomaticDelay.MaxRepairDate);
        }

        public void CanTerminateSignalement()
        {
            // Prepare
            var beginDate = new DateTime(2012, 2, 7);
            var panne = new Panne("FAKE", "Panne Grave", PanneSeverity.Serious) {Id = 1};
            var objetPatrimonial = new ObjetPatrimonial("FAKE", "Vieux Feu rouge") {Id = 1, Age = 17};
            var panneRepository = ServiceLocator.Current.GetInstance<IPanneRepository>();
            var objetPatrimonialRepository = ServiceLocator.Current.GetInstance<IObjetPatrimonialRepository>();
            panneRepository.Add(panne);
            objetPatrimonialRepository.Add(objetPatrimonial);
            var signalement = Signalement.CreateSignalement(objetPatrimonial, panne, beginDate, "Test", beginDate.AddDays(3), false);

            // Act
            signalement.Terminate();
            
            // Verify
            Assert.IsTrue(signalement.IsTerminated);
            Assert.IsTrue(signalement.ObjetPatrimonial.State == ObjetPatrimonialState.FullyOperational);

        }
    }
}
